/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package com.unwiredgrain.modeling.sscm.impl;

import com.unwiredgrain.modeling.sscm.Operation;
import com.unwiredgrain.modeling.sscm.OperationDirection;
import com.unwiredgrain.modeling.sscm.OperationParameter;
import com.unwiredgrain.modeling.sscm.SSCMPackage;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Operation</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link com.unwiredgrain.modeling.sscm.impl.OperationImpl#getDirection <em>Direction</em>}</li>
 *   <li>{@link com.unwiredgrain.modeling.sscm.impl.OperationImpl#getOperationParameters <em>Operation Parameters</em>}</li>
 *   <li>{@link com.unwiredgrain.modeling.sscm.impl.OperationImpl#getFullName <em>Full Name</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class OperationImpl extends TypedElementImpl implements Operation {
	/**
	 * The default value of the '{@link #getDirection() <em>Direction</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDirection()
	 * @generated
	 * @ordered
	 */
	protected static final OperationDirection DIRECTION_EDEFAULT = OperationDirection.COMMAND;

	/**
	 * The cached value of the '{@link #getDirection() <em>Direction</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDirection()
	 * @generated
	 * @ordered
	 */
	protected OperationDirection direction = DIRECTION_EDEFAULT;

	/**
	 * The cached value of the '{@link #getOperationParameters() <em>Operation Parameters</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getOperationParameters()
	 * @generated
	 * @ordered
	 */
	protected EList<OperationParameter> operationParameters;

	/**
	 * The default value of the '{@link #getFullName() <em>Full Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getFullName()
	 * @generated
	 * @ordered
	 */
	protected static final String FULL_NAME_EDEFAULT = null;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected OperationImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return SSCMPackage.Literals.OPERATION;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<OperationParameter> getOperationParameters() {
		if (operationParameters == null) {
			operationParameters = new EObjectContainmentEList<OperationParameter>(OperationParameter.class, this, SSCMPackage.OPERATION__OPERATION_PARAMETERS);
		}
		return operationParameters;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public String getFullName() {
		// DONE: implement this method to return the 'Full Name' attribute
		// Ensure that you remove @generated or mark it @generated NOT
		// throw new UnsupportedOperationException();
		StringBuilder sb = new StringBuilder();
		
		sb.append(getName());
		sb.append("(");
		
		if ((getOperationParameters() != null) && (getOperationParameters().size() > 0)) {
			for (OperationParameter op : getOperationParameters()) {
				
				sb.append(op.getTypeName());
				sb.append(" ");
				sb.append(op.getName());
				
				if (op != getOperationParameters().get(getOperationParameters().size() - 1)) {
					sb.append(", ");
				}
			}
		}
		
		sb.append(")");
		return sb.toString();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public OperationDirection getDirection() {
		return direction;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setDirection(OperationDirection newDirection) {
		OperationDirection oldDirection = direction;
		direction = newDirection == null ? DIRECTION_EDEFAULT : newDirection;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SSCMPackage.OPERATION__DIRECTION, oldDirection, direction));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case SSCMPackage.OPERATION__OPERATION_PARAMETERS:
				return ((InternalEList<?>)getOperationParameters()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case SSCMPackage.OPERATION__DIRECTION:
				return getDirection();
			case SSCMPackage.OPERATION__OPERATION_PARAMETERS:
				return getOperationParameters();
			case SSCMPackage.OPERATION__FULL_NAME:
				return getFullName();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case SSCMPackage.OPERATION__DIRECTION:
				setDirection((OperationDirection)newValue);
				return;
			case SSCMPackage.OPERATION__OPERATION_PARAMETERS:
				getOperationParameters().clear();
				getOperationParameters().addAll((Collection<? extends OperationParameter>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case SSCMPackage.OPERATION__DIRECTION:
				setDirection(DIRECTION_EDEFAULT);
				return;
			case SSCMPackage.OPERATION__OPERATION_PARAMETERS:
				getOperationParameters().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case SSCMPackage.OPERATION__DIRECTION:
				return direction != DIRECTION_EDEFAULT;
			case SSCMPackage.OPERATION__OPERATION_PARAMETERS:
				return operationParameters != null && !operationParameters.isEmpty();
			case SSCMPackage.OPERATION__FULL_NAME:
				return FULL_NAME_EDEFAULT == null ? getFullName() != null : !FULL_NAME_EDEFAULT.equals(getFullName());
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (direction: ");
		result.append(direction);
		result.append(')');
		return result.toString();
	}

} //OperationImpl
